package com.hqyj.project.service.impl;

import com.hqyj.project.entity.Dept;
import com.hqyj.project.mapper.DeptMapper;
import com.hqyj.project.service.DeptService;
import com.hqyj.project.utils.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DeptServiceImpl implements DeptService {

    @Autowired
    private DeptMapper deptMapper;

    @Override
    public CommonResult selectAll(Dept dept) {
        try {
            List<Dept> depts = deptMapper.selectAll(dept);
            return new CommonResult(200,"查询成功",depts);
        } catch (Exception e) {
            return new CommonResult(500,"查询失败");
        }
    }

    @Override
    public CommonResult updateById(Dept dept) {
        try {
            deptMapper.updateById(dept);
            return new CommonResult(200,"修改成功");
        } catch (Exception e) {
            return new CommonResult(500,"服务器出错,修改失败");
        }
    }

    @Override
    public CommonResult deleteById(Integer deptId) {
        try {
            deptMapper.deleteByDeptId(deptId);
            return new CommonResult(200,"删除成功");
        } catch (Exception e) {
            return new CommonResult(500,"服务器错误，删除失败");
        }
    }

    @Override
    public CommonResult insertOne(Dept dept) {
        try {
            deptMapper.insertOne(dept);
            return new CommonResult(200,"添加成功");
        } catch (Exception e) {
            return new CommonResult(500,"服务器错误，添加失败");
        }

    }
}
